package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/23.
 */
@HttpInlet(Conn.ORDER_COUPON_LIST)
public class OrderCouponListGet extends BaseAsyGet<OrderCouponListGet.OrderCouponListEntity> {

    public String user_id, classid, money;

    public OrderCouponListGet(AsyCallBack<OrderCouponListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected OrderCouponListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            OrderCouponListEntity orderCouponListEntity = new OrderCouponListEntity();

            JSONArray array = object.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject couponObject = array.optJSONObject(i);
                OrderCouponEntity orderCouponEntity = new OrderCouponEntity();

                orderCouponEntity.id = couponObject.optString("id");
                orderCouponEntity.title = couponObject.optString("title");
                orderCouponEntity.money = couponObject.optString("money");
                orderCouponEntity.total = couponObject.optString("total");
                orderCouponEntity.starttime = couponObject.optString("starttime");
                orderCouponEntity.endtime = couponObject.optString("endtime");
//                orderCouponEntity.type = couponObject.optString("type");

                orderCouponListEntity.orderCouponList.add(orderCouponEntity);
            }


            return orderCouponListEntity;
        }


        return null;
    }

    public static class OrderCouponListEntity {

        public List<OrderCouponEntity> orderCouponList = new ArrayList<>();

    }

    public static class OrderCouponEntity {

        public String id, title, money, total, starttime, endtime;//, type
    }


}
